package com.robot.topology.main;

import java.util.ArrayList;
import java.util.List;

import com.robot.io.WriteInFile;
import com.robot.topology.graph.domain.Edge;
import com.robot.topology.graph.domain.Graph;
import com.robot.topology.graph.domain.Vertex;
import com.robot.topology.strategy.aco.AntLikeI;
import com.robot.topology.tools.GraphTools;

public class MainAntLikeIRobot {

	public static void main(String[] args) throws Exception {

		//Self instantiate
		MainAntLikeIRobot main = new MainAntLikeIRobot();
		
		String filename;
		
		
		for(int i = 0; i < AntLikeI.K.length ; i++){
			//Write head of file
			filename = "100_ALI_"+AntLikeI.K[i];
			WriteInFile writeInformation = new WriteInFile("resources", filename,"CSV");
			writeInformation.initializeFile();
			
			for(int j = 0; j < 100 ; j++){
				//In each iteration change the number of ants in the colony
				Graph graphToExplore=main.buildGraph();
				//Write head of file
				if(j == 0){
					writeInformation.writeTextFile("Iteration;Strategy;"+graphToExplore.getLabelEdges());
				}
				
				AntLikeI ant1 = new AntLikeI(i,filename);
				ant1.runAlgorithm(graphToExplore);
				//break;
			}
			//break;
		}
		
	}


	public Graph buildGraph (){

		//Create the vertices
		Vertex vertexR1 = new Vertex("R1");
		Vertex vertexR3 = new Vertex("R3");
		Vertex vertexR4 = new Vertex("R4");
		Vertex vertexC1 = new Vertex("C1");
		Vertex vertexC2 = new Vertex("C2");

		//Create the list of Vertices
		List<Vertex> listVertex = new ArrayList<Vertex>();
		listVertex.add(vertexR1);
		listVertex.add(vertexR3);
		listVertex.add(vertexR4);
		listVertex.add(vertexC1);
		listVertex.add(vertexC2);

		//Get the initial weight at random
		//Double initialWeight=GraphTools.initializeWeightAtRandom();
		Double initialWeight = 0.5;

		//Create the edges
		Edge edgeR1C1 = new Edge("R1C1", vertexR1, vertexC1, (double)1);
		Edge edgeC1R3 = new Edge("C1R3", vertexC1, vertexR3, initialWeight);
		Edge edgeR3C2 = new Edge("R3C2", vertexR3, vertexC2,(double)1);
		Edge edgeC1C2 = new Edge("C1C2", vertexC1, vertexC2, initialWeight);
		Edge edgeC2R4 = new Edge("C2R4", vertexC2, vertexR4, (double)1);

		//Edges in a list
		List<Edge> listEdge = new ArrayList<Edge>();
		listEdge.add(edgeR1C1);
		listEdge.add(edgeC1R3);
		listEdge.add(edgeR3C2);
		listEdge.add(edgeC1C2);
		listEdge.add(edgeC2R4);

		// Create the graph
		Graph theGraph = new Graph(listVertex, listEdge);
		// Set the initial and goal verteces
		theGraph.setInitialVertex(vertexR1);
		theGraph.setGoalVertex(vertexR4);

		return theGraph;

	}


}
